﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
    public class Meal
    {
        #region Common
        public eMeal Data;

        public Meal()
        {
            Data = new eMeal();
        }

        ~Meal()
        {
        }

        public virtual void Dispose()
        {
        }

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cMeal objDAL = new cMeal();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cMeal objDAL = new cMeal();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
            cMeal objInfor = new cMeal();
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.MealID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cMeal objInfor = new cMeal();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        private void MappingData(cMeal objInfor)
        {
            objInfor.Name1 = Data.Name1;
            objInfor.Name2 = Data.Name2;
            objInfor.Name3 = Data.Name3;
        }

        private void ConvertData(cMeal objInfor)
        {
            Data.Name1 = objInfor.Name1;
            Data.Name2 = objInfor.Name2;
            Data.Name3 = objInfor.Name3;
        }
        public DataTable GetALL()
        {
            DataTable tbResult = new DataTable();
            cMeal objDAL = new cMeal();
            tbResult = objDAL.GetALL();
            return tbResult;
        }
        #endregion
    }
}
